package controller

import (
	"github.com/cy77cc/hioshop/models"
	"github.com/cy77cc/hioshop/utils"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

type RegionHandler struct {
}

func (RegionHandler) GetList(ctx *gin.Context) {
	res := utils.NewResponse()
	parentIdStr := ctx.Query("parentId")
	parentId, err := strconv.Atoi(parentIdStr)
	if err != nil {
		res.SetRes(1, "参数解析错误", err)
		ctx.JSON(http.StatusBadRequest, res)
		return
	}

	region := models.Region{}

	list, err := region.GetRegionListById(parentId)
	if err != nil {
		res.SetRes(1, "数据查询失败", err)
		ctx.JSON(http.StatusBadRequest, res)
		return
	}

	res.SetRes(0, "success", list)
	ctx.JSON(http.StatusOK, res)
}
